const Koa = require('koa'); // 引入Koa
const app = new Koa(); // 实例化Koa对象
const Router = require('koa-router'); // 引入koa-router
const router = new Router(); // 实例化路由对象
const fs = require('fs');
const path = require('path');
// 测试接口
const testRouter = new Router({prefix: '/test'});
fs.readFile(path.join(__dirname, '/data/Test.json'), 'utf8', (err, data) => {
	testRouter.get('/', ctx => {
		ctx.body = data;
	});
});
app.use(testRouter.routes());
// 首页接口
homeRouter = new Router({prefix: '/home'});
fs.readFile(path.join(__dirname, '/data/rdjd/Home.json'), 'utf8', (err, data) => {
	homeRouter.get('/', ctx => {
		ctx.body = data;
	});
});
app.use(homeRouter.routes());
// 联系我们接口
const messageListRouter = new Router({prefix: '/messageList'});
fs.readFile(path.join(__dirname, '/data/rdjd/MessageList.json'), 'utf8', (err, data) => {
	messageListRouter.get('/', ctx => {
		ctx.body = data;
	});
});
app.use(messageListRouter.routes());
// 新闻列表接口
const newsListRouter = new Router({prefix: '/newsList'});
fs.readFile(path.join(__dirname, '/data/rdjd/NewsList.json'), 'utf8', (err, data) => {
	newsListRouter.get('/', ctx => {
		ctx.body = data;
	});
});
app.use(newsListRouter.routes());
// 项目案例列表接口
const projectCaseListRouter = new Router({prefix: '/projectCaseList'});
fs.readFile(path.join(__dirname, '/data/rdjd/ProjectCaseList.json'), 'utf8', (err, data) => {
	projectCaseListRouter.get('/', ctx => {
		ctx.body = data;
	});
});
app.use(projectCaseListRouter.routes());
// 资质列表接口
const qualificationsListRouter = new Router({prefix: '/qualificationsList'});
fs.readFile(path.join(__dirname, '/data/rdjd/QualificationsList.json'), 'utf8', (err, data) => {
	qualificationsListRouter.get('/', ctx => {
		ctx.body = data;
	});
});
app.use(qualificationsListRouter.routes());
// 网站架构接口
const webSiteArchitectureRouter = new Router({prefix: '/webSiteArchitecture'});
fs.readFile(path.join(__dirname, '/data/rdjd/WebSiteArchitecture.json'), 'utf8', (err, data) => {
	webSiteArchitectureRouter.get('/', ctx => {
		ctx.body = data;
	});
});
app.use(webSiteArchitectureRouter.routes());
app.use(router.routes());
app.listen(3001, () => {
	console.log('server is starting at port 3001');
});
